package com.jckj.core.service.impl;

import com.jckj.core.annotation.CurrentDataSource;
import com.jckj.core.dao.ParkNotifyMapper;
import com.jckj.core.db.DataSourceEnum;
import com.jckj.core.entity.ParkNotify;
import com.jckj.core.entity.ParkNotifyExample;
import com.jckj.core.exception.ServiceException;
import com.jckj.core.service.ParkNotifyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author:liukuan
 * @date :2018-01-29
 */
@Service
@Transactional(readOnly = true,rollbackFor = ServiceException.class)
public class ParkNotifyServiceImpl implements ParkNotifyService {

    private static Logger LOGGER = LoggerFactory.getLogger(ParkNotifyServiceImpl.class);

    @Autowired
    ParkNotifyMapper parkNotifyMapper;


    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int deleteById(String id) {
        int num=0;
        try {
            num= parkNotifyMapper.deleteByPrimaryKey(id);
        } catch (Exception e) {
            LOGGER.error("删除园区信息:%s", e.fillInStackTrace());
            throw new ServiceException("删除园区信息出错",e);
        }
        return num;
    }


    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int insert(ParkNotify record) {
        int num=0;
        try {
            num= parkNotifyMapper.insertSelective(record);
        } catch (Exception e) {
            LOGGER.error("新增园区信息:%s", e.fillInStackTrace());
            throw new ServiceException("新增园区信息出错",e);
        }
          return num;
    }


    @Override
    @CurrentDataSource(DataSourceEnum.SLAVE)
    public List<ParkNotify> findByExample(ParkNotifyExample example) {
        return parkNotifyMapper.selectByExample(example);
    }


    @Override
    @CurrentDataSource(DataSourceEnum.SLAVE)
    public ParkNotify findById(String id) {
            return parkNotifyMapper.selectByPrimaryKey(id);
    }


    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int updateById(ParkNotify record) {
        int num=0;
        try {
            num=parkNotifyMapper.updateByPrimaryKeySelective(record);
        } catch (Exception e) {
            LOGGER.error("修改园区信息:%s", e.fillInStackTrace());
            throw new ServiceException("修改园区信息出错",e);
        }
          return num;
    }



    /**
     * @param parkNotify
     * @param id
     * @return
     */
    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int updateByNotifyId(ParkNotify parkNotify, String id) {
         int num=0;
        try {
            ParkNotifyExample example = new ParkNotifyExample();
            ParkNotifyExample.Criteria criteria = example.createCriteria();
            criteria.andNotifyIdEqualTo(id);
            parkNotifyMapper.updateByExampleSelective(parkNotify,example);
        } catch (Exception e) {
            LOGGER.error("根据通知公告修改园区信息:%s", e.fillInStackTrace());
            throw new ServiceException("根据通知公告修改园区信息出错",e);
        }
        return num;
    }



    /**
     * @param
     * @return
     */
    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int deleteByNotifyId(String id) {
         int num=0;
        try {
            ParkNotifyExample example = new ParkNotifyExample();
            ParkNotifyExample.Criteria criteria = example.createCriteria();
            criteria.andNotifyIdEqualTo(id);
            parkNotifyMapper.deleteByExample(example);
        } catch (Exception e) {
            LOGGER.error("根据通知公告删除园区信息:%s", e.fillInStackTrace());
            throw new ServiceException("根据通知公告删除园区信息出错",e);
        }
          return num;
    }


}
